<!-- f r o m 7 5  2 7 1  8 9 2 0 -->
<template>
  <a-row :gutter="24">
    <a-col :md="24">

      <a-tabs v-model:activeKey="activeKey" type="editable-card" @edit="onEdit" @add="onAdd">
        <a-tab-pane v-for="pane in panes" :key="pane.key" :tab="pane.title" :closable="pane.closable">
<!--          {{ quoteTemplateItems[pane.key]}}-->
                <a-card ::bordered="false">
                  <!-- 查询区域 -->
<!--                  <div class="table-page-search-wrapper">-->
<!--                    &lt;!&ndash; 搜索区域 &ndash;&gt;-->
<!--                    <a-form layout="inline" @keyup.enter.native="searchQuery">-->
<!--                      <a-row :gutter="24">-->
<!--                        <a-col :md="18" :sm="24">-->
<!--                          <a-form-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
<!--                            <a-input placeholder="请输入名称查询" v-model="queryParam.name"></a-input>-->
<!--                          </a-form-item>-->
<!--                        </a-col>-->
<!--                        <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">-->
<!--                          <a-col :md="6" :sm="24">-->
<!--                            <a-button type="primary" @click="searchQuery">查询</a-button>-->
<!--                            <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>-->
<!--                          </a-col>-->
<!--                        </span>-->
<!--                      </a-row>-->
<!--                    </a-form>-->
<!--                  </div>-->
                  <!-- 操作按钮区域 -->
                  <div class="table-operator"  style="margin-top: 5px">
                    <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
                  </div>
                  <!-- table区域-begin -->
                  <div>
                    <a-table
                      ref="table"
                      size="small"
                      bordered
                      rowKey="id"
                      :columns="columns"
                      :dataSource="dataSource"
                      :pagination="ipagination"
                      :scroll="scroll"
                      :loading="loading"
                      :rowSelection="{type: 'radio', selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                      @change="handleTableChange">
                      <span slot="action" slot-scope="text, record">
                        <a @click="handleEdit(record)">编辑</a>
                        <a-divider type="vertical" />
                        <a-popconfirm title="确定删除吗?" @confirm="() => deleteTemplate(record.id)">
                          <a>删除</a>
                        </a-popconfirm>
                      </span>
                      <!-- 状态渲染模板 -->
                      <template slot="customRenderEnabledFlag" slot-scope="enabled">
                        <a-tag v-if="enabled" color="green">启用</a-tag>
                        <a-tag v-if="!enabled" color="orange">禁用</a-tag>
                      </template>
                      <template slot="customRenderFlag" slot-scope="isDefault">
                        <a-tag v-if="isDefault" color="green">是</a-tag>
                        <a-tag v-if="!isDefault" color="orange">否</a-tag>
                      </template>
                    </a-table>
                  </div>
                  <!-- table区域-end -->
                  <!-- 表单区域 -->
                  <quote-template-modal ref="modalForm" @ok="modalFormOk"></quote-template-modal>
                </a-card>
        </a-tab-pane>
      </a-tabs>
    </a-col>
  </a-row>
</template>
<!-- BY cao_yu_li -->
<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import JDate from '@/components/jeecg/JDate'
  import QuoteTemplateModal from '@views/quote/modules/QuoteTemplateModal.vue'
  import { getAction, postAction } from '@api/manage'
  export default {
    name: "QuoteTemplateItemTable",
    mixins:[JeecgListMixin],
    components: {
      QuoteTemplateModal,
      JDate
    },
    props:{
      // quoteCategoryId:{type:Number,required:true,default:0},
    },
    data () {
      return {
        // localQuoteCategoryId: this.quoteCategoryId,
        quoteTemplate:{},
        panes:[],
        activeKey:'',
        quoteTemplateSubSystems:[],
        quoteTemplateItems:{},
        // 表头
        columns: [
          {
            title: '操作',
            dataIndex: 'action',
            width: 30,
            align:"center",
            scopedSlots: { customRender: 'action' },
          },
          { title: '名称', dataIndex: 'name', width: 80, align: "left"},
          { title: '所属分类', dataIndex: 'serialNo', width: 50, align: "left"},
          { title: '材料数量', dataIndex: 'initialAmount', width: 50, align: "left"},
          { title: '备注', dataIndex: 'remark', width: 100, align: "left"},
          // { title: '状态',dataIndex: 'enabled',width:60,align:"center",
          //   scopedSlots: { customRender: 'customRenderEnabledFlag' }
          // }
        ],
        url: {
          list: "/quote/template/item/list?quoteTemplateId=-1",
          delete: "/quote/template/delete"
        }
      }
    },
    computed: {

    },
    methods: {
      handleEdit: function (record) {
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = "编辑";
        this.$refs.modalForm.disableSubmit = false;
        if(this.btnEnableList.indexOf(1)===-1) {
          this.$refs.modalForm.isReadOnly = true
        }
      },
      handleAdd: function () {
        this.$refs.modalForm.add(this.localQuoteCategoryId);
        this.$refs.modalForm.title = "新增";
        this.$refs.modalForm.disableSubmit = false;
        if(this.btnEnableList.indexOf(1)===-1) {
          this.$refs.modalForm.isReadOnly = true
        }
      },
      deleteTemplate(id) {
        var that = this
        this.$confirm({
          title: '确认删除',
          content: '确定要删除吗?',
          onOk: function () {
            postAction(that.url.delete, {id: id}).then((res) => {
              if (res.code == 200) {
                that.$message.success(res.data.message)
                that.reloadList(that.localQuoteCategoryId)
              } else {
                that.$message.warning(res.data.message)
              }
            })
          }
        })
      },
      reloadList(quoteTemplate) {
        this.quoteTemplate = quoteTemplate
        // this.url.list = "/quote/template/item/list?quoteTemplateId="+quoteTemplate.id;
        // this.loadData();
        getAction("/quote/template/item/list?quoteTemplateId="+quoteTemplate.id,{}).then(res => {
          if (res.code == 200) {
            console.log(res.data)
            this.panes = [];
            for (let i = 0; i < res.data.subSystems.length; i++) {
              this.panes.push({title:res.data.subSystems[i],key:res.data.subSystems[i]})
            }
            console.log(this.panes);
          }
        })
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        console.log('Selected Key:', selectedRowKeys);
        console.log('Selected Row:', selectionRows);
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      onEdit(targetKey){

      },
      onAdd(){
        console.log("onAdd");
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>